/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
function draw(itemTitle,dataList) {
  var max = 0, min = 0;
  for (var i in dataList) {

    if(isNaN(dataList[i]['value'])){
      continue
    }
    if (dataList[i]['value'] > max) {
      max = dataList[i][['value']];
    }
    if (dataList[i]['value'] < min) {
      min = dataList[i]['value'];
    }
  }

  var myChart = echarts.init(document.getElementById('main'));

  option = {
    tooltip: {
      formatter: function(params, ticket, callback) {
        return params.seriesName + '<br />' + params.name + '：' + params.value;
      },//数据格式化
    },
    visualMap: {
      min: min,
      max: max,
      left: 'left',
      top: 'bottom',
      text: ['高', '低'],//取值范围的文字
      inRange: {
        color: ['#ff5050', '#512020'],//取值范围的颜色
      },
      show: true,//图注
    },
    geo: {
      map: 'china',
      roam: false,//不开启缩放和平移
      zoom: 1.23,//视角缩放比例
      label: {
        normal: {
          show: true,
          fontSize: '10',
          formatter: function (params,value) {
            //return '';
            var name = params['name'];
            for (var i = 0; i < option.series[0].data.length; i++) {
              if (option.series[0].data[i].name == name) {
                return name +":"+ option.series[0].data[i].value;
              }
            }
          },
          color: 'rgba(0,0,0,0.7)',
        },
      },
      itemStyle: {
        normal: {
          borderColor: 'rgba(0, 0, 0, 0.2)',
        },
        emphasis: {
          areaColor: '#F3B329',//鼠标选择区域颜色
          shadowOffsetX: 0,
          shadowOffsetY: 0,
          shadowBlur: 20,
          borderWidth: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)',
        },
      },
    },
    series: [
      {
        name: itemTitle,
        type: 'map',
        geoIndex: 0,
        data: dataList,
      },
    ],
  };
  myChart.setOption(option);
  myChart.on('click', function(params) {
    // alert(params.name);
  });

}